<?php
/* @var $this InsertController */
/* @var $model Insert */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'insert-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>


	<?php echo $form->errorSummary($model); 

	$sql = "Select * from inventory";
    $dataReader =  Yii::app()->db->createCommand($sql)->query();
    while(($row = $dataReader->read())!==false) {$data = $row;}
	?>

<br>
<b>Quantity In Stock:</b>
<?php echo $data['qty_in_stock']; ?>
<br>
<br>

		 <div class="row">
        <?php 
                $criteria = new CDbCriteria();
                $criteria->select = 'id';
                $criteria->condition = 'username=:name';
                $criteria->params = array(':name'=>Yii::app()->user->name);
        ?>
		
                <!-- <?php echo $form->labelEx($model,'User_id'); ?> !-->
                <?php echo $form->dropDownList($model, 'user_id', CHtml::listData(User::model()->findAll('username = :a', array(':a'=>Yii::app()->user->name)), 'id', 'fname'), array('style' => 'display:none')); ?>
                <?php echo $form->error($model,'User_id'); ?> 
        </div>
		

	<?php
		if(isset($_GET['id'])){
		echo '<div class="row" style="display:none;">'; 
		}else{
    	echo '<div class="row">';
		}
	?>
		<?php echo $form->labelEx($model,'inventory_id'); ?>
	<?php $name = array();
	        $model1 = Inventory::model()->findAll();
	        foreach ($model1 as $model2)
			$name[$model2->id] = $model2->id;
			echo $form->dropDownList($model, 'inventory_id', $name,
			array('prompt' => 'Select Inventory No.')); ?>
			<?php if(isset($_GET['id'])){
				echo $form->textField($model,'inventory_id',array('size'=>45,'maxlength'=>45, 'value'=>$_GET['id']));
			}
			echo $form->error($model,'inventory_id'); ?>
	</div>
	

	<div class="row">
		<?php echo $form->labelEx($model,'date'); ?>
	<?php $this-> widget ('zii.widgets.jui.CJuiDatePicker', array('model'=>$model, 'attribute'=>'date','options' => array ('dateFormat' => 'yy-mm-dd','yearRange' => '-20:+20','changeYear' => 'true','changeMonth' => 'true',),));?>
		<?php echo $form->error($model,'date'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'qty'); ?>
		<?php echo $form->textField($model,'qty'); ?>
		<?php echo $form->error($model,'qty'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'comment'); ?>
		<?php echo $form->textArea($model,'comment',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'comment'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->